//
//  JHExplainViewController.m
//  JuniRengLish_iOS
//
//  Created by Maiyou on 2019/5/23.
//  Copyright © 2019 revogi. All rights reserved.
//

#import "JHExplainViewController.h"
#import "JHExplainInfoViewCell.h"
#import "CWPageControl.h"

@interface JHExplainViewController () <CWCarouselDatasource, CWCarouselDelegate>

@property (nonatomic, strong) CWCarousel *carousel;

@end

@implementation JHExplainViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"详细解读";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self jxt_showAlertWithTitle:@"" message:@"[点击任意一一个英文单词,可实时翻译及播放语音哦~]" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) {
        alertMaker.addActionCancelTitle(@"确定");
    } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) {
        
    }];
    
    [self configureUI];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.carousel controllerWillAppear];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.carousel controllerWillDisAppear];
}

- (void)configureUI
{
    CWFlowLayout *flowLayout = [[CWFlowLayout alloc] initWithStyle:3];
    
    /*  使用frame创建视图  */
    CWCarousel *carousel = [[CWCarousel alloc] initWithFrame:CGRectMake(0, 20, JKScreenW, JKScreenH - kTabbarSafeBottomMargin - kStatusBarAndNavigationBarHeight - 20)
             delegate:self
           datasource:self
           flowLayout:flowLayout];
    carousel.isAuto = NO;
    carousel.endless = NO;
    carousel.autoTimInterval = 0;
    carousel.pageControl.hidden = YES;
    carousel.backgroundColor = [UIColor whiteColor];
    [carousel registerNibView:@"JHExplainInfoViewCell" identifier:@"cellid"];
    [self.view addSubview:carousel];
    [carousel freshCarousel];
    self.carousel = carousel;
    
    carousel.currentIndexPath = [NSIndexPath indexPathForItem:self.selectIndex + 1 inSection:0];
    [self.carousel.carouselView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.selectIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
}

- (NSInteger)numbersForCarousel {
    return self.dataArray.count;
}

#pragma mark - Delegate
- (UICollectionViewCell *)viewForCarousel:(CWCarousel *)carousel indexPath:(NSIndexPath *)indexPath index:(NSInteger)index
{
    JHExplainInfoViewCell *cell = [carousel.carouselView dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];
    cell.lrcModel = self.dataArray[index];
    cell.currentVC = self;
    return cell;
}

- (void)CWCarousel:(CWCarousel *)carousel didSelectedAtIndex:(NSInteger)index
{
    NSLog(@"...%ld...", (long)index);
}


- (void)CWCarousel:(CWCarousel *)carousel didStartScrollAtIndex:(NSInteger)index indexPathRow:(NSInteger)indexPathRow {
    NSLog(@"开始滑动: %ld", index);
}


- (void)CWCarousel:(CWCarousel *)carousel didEndScrollAtIndex:(NSInteger)index indexPathRow:(NSInteger)indexPathRow {
    NSLog(@"结束滑动: %ld", index);
}

@end
